﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Dispatcher;

namespace cn.sunchis.pvuv.sdk.config
{
    /// <summary>
    /// 扩展ASP.Net的Http Controller分发器
    /// <para>@Author 许亮</para>
    /// <para>@Create 2018-7-4 16:04:30</para>
    /// </summary>
    public class PvuvHttpControllerDispatcher : HttpControllerDispatcher
    {
        private PvuvKafkaProducer pvuvKafkaProducer;

        /// <summary>
        /// 构造器重载
        /// </summary>
        /// <param name="configuration"></param>
        public PvuvHttpControllerDispatcher(HttpConfiguration configuration) : base(configuration) 
        {
            this.pvuvKafkaProducer = new PvuvKafkaProducer();
        }

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            // 记录一次PVUV
            this.pvuvKafkaProducer.newVisit(request, cancellationToken);

            return base.SendAsync(request, cancellationToken);
        }
    }
}
